import Vue from 'vue'
import axios from 'axios'
import Qs from 'qs'
//正式
export const baseURL='http://ins-api.goboosoft.com/';
//测试
//  export const baseURL='  http://webdoc.boxinyao.com/'; 





 const service = axios.create({
    baseURL: baseURL,
    timeout: 0,
    
})

service.interceptors.request.use(config => {
   
    config.headers={  'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' }
    
    return config
}, (error) => {
    console.warn("request.error")
    return errorHandler(error)
})

service.interceptors.response.use((res) => {

    return res
}, (error) => {
    console.warn("response.error")
    return errorHandler(error)
})

// GET 请求
export function get(url, params , headers = {}) {

 

    return service.get(url,{
        params,
        headers
    }).then((res) => {
  
        // console.log("res",res.data)
        if(res.data.code!=200){
           
        }
        return Promise.resolve(res.data)
    }).catch((err) => {
      
        return errorHandler(err)
    })
}
// POST 请求
export function post(url,  params, headers = {}){
  

    return service.post(url,Qs.stringify(params)  , {
        headers
    }).then((res) => {
    
       // console.log(url,res.data)
        if(res.data.code!=200){
          //  Toast({ message: res.data.data, position: "bottom" });
        }
        return Promise.resolve(res.data)
    }).catch((err) => {
      
        return errorHandler(err)
    })
} 
const errorHandler=(err)=>{
    console.log("err",err) 
}


export const _API = {
    // selectShopByid:"haha"
    doLogin: query => post('/index/doLogin', query),  //登录

      getUser: query => get('index/getUser', query),  //用户列表

    addUser: query => post('index/createUser', query),  //添加用户


    deleteUser: query => get('index/deleteUser', query),  //删除用户


    getList: query => get('index/getList', query),  //文本编辑列表

    saveContent: query => post('index/saveContent', query),  //添加文本编辑

    deleteContent: query => post('index/deleteContent', query),  //删除文本编辑

    getLog: query => post('index/getLog', query),  //添加用户
   
    
  }


 